﻿@{
    Layout = "_QuartzNetUILayout";
}
<div>
    <div v-loading="loading">
        <el-card class="box-card">
            <div slot="header" class="clearfix"><span>通知邮箱设置</span></div>
            <div class="text item">
                <el-form :inline="true" :model="emaillForm" status-icon :rules="rules" ref="emaillForm" label-width="100px" size="small">
                    <el-form-item label="账号" prop="emailAccount">
                        <el-input type="text" v-model="emaillForm.emailAccount" placeholder="请输入邮箱账号"></el-input>
                    </el-form-item>
                    <el-form-item label="密码" prop="emaillPass">
                        <el-input type="password" v-model="emaillForm.emaillPass" placeholder="请输入邮箱密码"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @@click="submitForm('emaillForm')">提交</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </el-card>
        <div style="height:10px;"></div>
@*         <el-card class="box-card">
            <div slot="header" class="clearfix"><span>企业微信通知设置</span></div>
            <div class="text item">
                <el-form :inline="true" :model="workweixinForm" status-icon label-width="100px" size="small">
                    <el-form-item label="发送通知" prop="sendWorkWeixin">
                        <el-switch v-model="workweixinForm.sendWorkWeixin" :active-text="workweixinText" @@change="changeWorkerWeiXin"></el-switch>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @@click="saveWorkerWeiXin">提交</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </el-card> *@
    </div>
</div>
@section Scripts{
    <script>
        new Vue({
            el: "#main",
            data: {
                activeIndex: '4',
                loading: false,

                workweixinText: "不发送企业微信通知",
                workweixinForm: {
                    id: 0,
                    code: 'SettingWorkerWeiXin',
                    sendWorkWeixin: false
                },
                emaillForm: {
                    id: 0,
                    code: 'SettingEmaill',
                    emailAccount: '',
                    emaillPass: '',
                },
                rules: {
                    emailAccount: [{ required: true, message: '请输入邮箱地址', trigger: 'blur' }, { type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur'] }],
                    emaillPass: [{ required: true, message: '请输入密码', trigger: 'blur' }, { min: 1, max: 500, message: '长度在 1 到 500 个字符', trigger: 'blur' }],
                }
            },
            created: function () {
                this.initEmaillData();
                this.initWorkWeixinData();
            },
            methods: {
                initEmaillData() {
                    var that = this;
                    that.loading = true;
                    axios("/job/getstingbycode?data=" + that.emaillForm.code).then(function (res) {
                        if (res.data.code == 200) {
                            that.emaillForm = res.data.data;
                            that.loading = false;
                        }
                        else if (res.data.code == 204) {
                            that.loading = false;
                        } else {
                            that.$message({ message: res.data.message, center: true, type: 'error' });
                            that.loading = false;
                        }
                    });
                },
                initWorkWeixinData() {
                    var that = this;
                    that.loading = true;
                    axios("/job/getstingbycode?data=" + "SettingWorkerWeiXin").then(function (res) {
                        if (res.data.code == 200) {
                            that.workweixinForm = res.data.data;
                            that.changeWorkerWeiXin();
                            that.loading = false;
                        } else if (res.data.code == 204) {
                            that.loading = false;
                        } else {
                            that.$message({ message: res.data.message, center: true, type: 'error' });
                            that.loading = false;
                        }
                    });
                },
                submitForm(formName) {
                    var that = this;
                    this.$confirm('确定提交此设置?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => {
                        this.$refs[formName].validate((valid) => {
                            if (valid) {
                                axios.post("/job/saveSetting", that.emaillForm).then(function (res) {
                                    if (res.data.code == 200) {
                                        ELEMENT.MessageBox.alert(res.data.message, "系统信息", { type: 'success', callback: () => { } });
                                    } else {
                                        ELEMENT.MessageBox.alert(res.data.message, "系统信息", { type: 'info', callback: () => { } });
                                    }
                                });
                            }
                        });
                    });
                },
                changeWorkerWeiXin() {
                    var that = this;
                    that.workweixinText = ((that.workweixinForm == null || that.workweixinForm.sendWorkWeixin == false) ? "不发送企业微信通知" : "发送企业微信通知");
                },
                saveWorkerWeiXin() {
                    var that = this;
                    this.$confirm('确定提交此设置?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => {
                        axios.post("/job/saveSetting", that.workweixinForm).then(function (res) {
                            if (res.data.code == 200) {
                                that.changeWorkerWeiXin();
                                ELEMENT.MessageBox.alert(res.data.message, "系统信息", { type: 'success', callback: () => { } });
                            } else {
                                ELEMENT.MessageBox.alert(res.data.message, "系统信息", { type: 'info', callback: () => { } });
                            }
                        });
                    });
                }
            }
        });
    </script>
}
